package hk.mrtomato.control;

import hk.mrtomato.dto.MruserDTO;
import hk.mrtomato.help.ActionForward;
import hk.mrtomato.model.MrBoardService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ibatis.sqlmap.engine.mapping.sql.dynamic.elements.IsNullTagHandler;

public class MrUpdateInfoAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		MrBoardService manager = MrBoardService.getInstance();
		String id=request.getParameter("id");
		String password=request.getParameter("password");
		String name=request.getParameter("name");
		String address=request.getParameter("address");
		
		int count=0;
		System.out.println("1");
		ActionForward forward = new ActionForward();
		if(id==null||name==null||password==null||address==null){
			System.out.println("null");
			count=0;
		}else{
			manager.updateMruser(new MruserDTO(id, password, 3, name, address));
			count=1;
			System.out.println("2");
		}
		
		if(count>0){
			MruserDTO mrDto = manager.getMrUser(id);
			request.setAttribute("mrDto", mrDto);
			forward.setUrl("updinfo");
		}else{
			System.out.println("error");
		}
		return forward;
	}
}
